package com.julu.o2o.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 时间工具类
 * @author yangtonggan
 * @date 2016-5-3
 */
public class DateUtil {
	/**
	 * 自定义时间格式化字符串
	 * 值的格式是yyyyMMddHHmmss，如20151231235900，即是2015-12-31 23:59:00，long类型
	 * @return
	 */
	public static Long myNowTime(){
		try{
			Date d = new Date();
			DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINESE);
			String str = sdf.format(d);			
			Pattern pattern = Pattern.compile("[^0-9]");
		    Matcher matcher = pattern.matcher(str);
		    String t = matcher.replaceAll("");			
			Long time = Long.parseLong(t);
			return time;
		}catch(Exception e){
			throw new RuntimeException(e);
		}		
	}
	/**
	 * 获取自定义时间格式化
	 * @param str  值的格式是yyyyMMddHHmmss，如20151231235900，即是2015-12-31 23:59:00
	 * @return
	 */
	public static Long myTimeFormt(String str){
		try{
			Pattern pattern = Pattern.compile("[^0-9]");
		    Matcher matcher = pattern.matcher(str);
		    String t = matcher.replaceAll("");			
			Long time = Long.parseLong(t);
			return time;		
		}catch(Exception e){			
		}	
		return null;	
	}
}
